package com.lb.activiti.variable;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * 流程变量测试
 */
public class VariableTest {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    @Test
    public void test1(){
        //部署流程定义
        DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
        deploymentBuilder.addClasspathResource("com/lb/activiti/variable/qjlc.bpmn");
        Deployment deployment = deploymentBuilder.deploy();
        System.out.println(deployment);
    }

    @Test
    public void test2(){
        //设置流程变量：启动流程实例时设置
        String processDefinitionKey="myProcess_1";
        Map<String,Object> variables = new HashMap<>();
        variables.put("k1","v1");
        variables.put("k2","v2");
        ProcessInstance processInstance = processEngine.getRuntimeService()
                .startProcessInstanceByKey(processDefinitionKey,variables);
        System.out.println(processInstance.getId());
    }

    @Test
    public void test3(){
        //办理任务
        String taskId="302";
        processEngine.getTaskService().complete(taskId);
    }
}
